# Time-stamp: <10 May 00 11:05:34 giron1>

=head1 NAME

SIMPL_REP - Package for simplification with repeated structures -

=head1 SYNOPSIS

 use SIMPL_REP;

=head1 DESCRIPTION

This program takes in input the recognition part, and simplifies it with
repeated structures (makes mincount start with 0 or 1,and the maxcount start
with 1 or infinit)

=head1 AUTHOR

 Daniela Raddino, Stefan Rapp, Franck Giron
 $Id: SIMPL_REP.pm,v 1.1 2007/10/08 09:26:03 schweitz Exp $

=head1 LOG

 $Log: SIMPL_REP.pm,v $
 Revision 1.1  2007/10/08 09:26:03  schweitz
 version 2.4, lib vergessen

 Revision 1.1  2000/05/12 15:02:55  giron1
 First package version


=cut

package SIMPL_REP;

#----------------------------------------------------------------------

=head1 FUNCTIONS

Here is a description of the functions used

=head2 simpl_rep


=cut

sub simpl_rep {
  my ($recgram_point)=@_;
 
  foreach (sort keys %$recgram_point) {
    my $lang_point=$$recgram_point{$_};
    $debug && warn "$_: lang_point=$lang_point\n";
    foreach (sort keys %$lang_point) {
      my $g_section_point=$$lang_point{$_};
      $debug && warn "$_: $g_section_point\n";
      my @array_g = @$g_section_point;
      my @temp_array_g;
      $temp_array_g[0]=$array_g[0];
      $length_g=scalar(@array_g);
      my ($g);
      for ($g=1;$g<=$length_g-1;$g++) {              
	if (not defined($array_g[$g][0])) {push @temp_array_g,$array_g[$g];}
	else {
	  my $sub_pointer=$array_g[$g];
	  @sub_array=@$sub_pointer;
	  (@point_array)=scan_array(@sub_array);
	  push @temp_array_g,@point_array;
	  
	}
      }
      @$g_section_point=@temp_array_g;
    }
  }
}
1;
#subroutine------------------------------------------------------------- 
               
sub scan_array {
  my @one_array=@_;

  my @temp_array;
  $temp_array[0]=$one_array[0];
  my $length=scalar(@one_array); 
  my $i;
  for ($i=1;$i<=$length-1;$i++) {
    if (not defined($one_array[$i][0])) {push @temp_array,$one_array[$i];}
    else { 
      my $sub_array_pointer=$one_array[$i];
      my @sub_array=@$sub_array_pointer;
      my (@new_array)=scan_array(@sub_array);
      push @temp_array,@new_array;
    }
  }
  my %first;
  my %second;
  my @first_array=@temp_array;
  my @second_array=@temp_array;
  my $mincount=$one_array[0]->{mincount};
  my $maxcount=$one_array[0]->{maxcount};
  my @out_array;
  if (not defined($maxcount))  {	
    $first{mincount}=1;
    $first{maxcount}=1;
    $first_array[0]=\%first;
    for ($n=1;$n<=$mincount;$n++) {push @out_array,\@first_array;}
    $second{mincount}=0;
    $second{maxcount}=undef;
    $second_array[0]=\%second;
    push @out_array,\@second_array;
  }else {
    $first{mincount}=1;
    $first{maxcount}=1; 
    $first_array[0]=\%first;                 
    for ($n=1;$n<=$mincount;$n++) {
      push @out_array, \@first_array; }
    $second{mincount}=0;
    $second{maxcount}=1;
    $second_array[0]=\%second;
    for ($n=1;$n<=$maxcount-$mincount;$n++) {
      push @out_array, \@second_array; }
  }
  return @out_array;
}
1;
